package com.sise.controller.wechat;

import com.sise.bean.CodeMsg;
import com.sise.entity.ProductLike;
import com.sise.service.IProductInfoService;
import com.sise.service.IProductLikeService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zj
 */
@RestController
@RequestMapping("/sise/wechat/product-like")
public class WechatProductLikeController {

    @Resource
    private IProductInfoService productInfoService;

    @Resource
    private IProductLikeService productLikeService;

    @PostMapping("/addLike")
    public String addLike(@RequestBody ProductLike productLike) {
        boolean isAdd = productLikeService.addLike(productLike);
        if (isAdd) {
            productInfoService.addProductLike(productLike.getProductId());
            return "添加喜欢成功！";
        }
        return "添加喜欢失败！";
    }

    @PostMapping("/cancelLike")
    public String cancelLike(@RequestBody ProductLike productLike) {
        boolean isCancel = productLikeService.cancelLike(productLike);
        if (isCancel) {
            productInfoService.cancelProductLike(productLike.getProductId());
            return "取消喜欢成功！";
        }
        return "取消喜欢失败！";
    }

    @PostMapping("/isLikeAndCount")
    public CodeMsg isLikeAndCount(@RequestBody ProductLike productLike) {
        return productLikeService.isLikeAndCount(productLike);
    }
}
